//
//  BaseTableViewController.swift
//  weibo
//
//  Created by Mike on 15/5/10.
//  Copyright (c) 2015年 Mike. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController {

//    var isLogin: Bool = false
    var isLogin: Bool = sharedUserAccount != nil
    var mainLoginView: MainLoginView!
    override func loadView() {
        if isLogin {
            // 显示tableView
            super.loadView() // 一定要调用父类的方法
            return
        } else {
            // 登录界面
//            self.view = UIView()
//            self.view.backgroundColor = UIColor.whiteColor()
            
            // 从xib加载view
            self.mainLoginView = NSBundle.mainBundle().loadNibNamed("MainLoginView", owner: nil, options: nil).last as! MainLoginView
            self.mainLoginView.delegate = self
            
            self.view = mainLoginView
            
            // 添加导航栏按钮
            self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registDidClicked:")
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginDidClicked:") // 在appDelegate设置外观
            
        }
    }
}
extension BaseTableViewController:MainLoginViewDelegate {
    func loginDidClicked(view: MainLoginView) {
//        println("处理登录事件")
        let sb = UIStoryboard(name: "OAuth", bundle: nil)
        presentViewController(sb.instantiateInitialViewController() as! UIViewController, animated: true, completion: nil)
    }
    func registDidClicked(view: MainLoginView) {
        println("处理注册事件")
    }
}